package com.ilxqx.framework.schedule.config;

import com.ilxqx.framework.schedule.constant.JobDetailConstants;
import com.ilxqx.framework.schedule.job.FileDeletionJob;
import com.ilxqx.framework.schedule.job.TestJob;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * JobDetail配置类
 * @author venus
 */
@Configuration
public class JobDetailBeanConfig {

    /**
     * 构建一个JobDetail
     * @param jobClass job类
     * @param jobKey job标识
     * @param desc job描述
     * @return jobDetail对象
     */
    private JobDetail newJobDetail(Class<? extends Job> jobClass, JobKey jobKey, String desc) {
        return JobBuilder
            .newJob(jobClass)
            .storeDurably()
            .withIdentity(jobKey)
            .withDescription(desc)
            .build();
    }

    /**
     * 测试任务
     * @return JobDetail对象
     */
    @Bean
    public JobDetail testJobDetail() {
        return this.newJobDetail(TestJob.class,
            JobDetailConstants.TEST_JOB_KEY,
            "测试任务");
    }

    /**
     * 文件删除任务
     * @return JobDetail对象
     */
    @Bean
    public JobDetail fileDeletionJobDetail() {
        return this.newJobDetail(FileDeletionJob.class,
            JobDetailConstants.FILE_DELETION_KEY,
            "文件删除任务");
    }

}
